﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;

public partial class Pages_ManagerPages_updateCompetition : System.Web.UI.Page
{
    int id;
    protected void Page_Load(object sender, EventArgs e)
    {
        ManagerBUS m = new ManagerBUS();
        Competition comp = new Competition();
        id= Convert.ToInt16(Request.QueryString["id"].ToString());
        DataSet ds=new DataSet();
        ds=m.getStaffOfComp(id);
        DataSet ds1 = new DataSet();
        ds1 = m.getAllStaff();
        comp = m.searchCompetitionById(id);
        lblCompName.Text = comp.Name;
        lblFirstPrize.Text = comp.FirstPrize;
        lblSecPrize.Text = comp.SecondPrize;
        lblThirdPrize.Text = comp.ThirdPrize;
        lblStartDate.Text = comp.StartDate;
        lblEndDate.Text = comp.EndDate;
        lblDescription.Text = comp.Description;
        lblQuotation.Text = comp.Quotation;
        imgIcon.ImageUrl = "~/Images/Competition/" + comp.CompImage;
        grvStaff.DataSource = ds.Tables[0];
        grvStaff.DataBind();
        txtCompetitionName.Text = comp.Name;
        txtFirstPrize.Text = comp.FirstPrize;
        txtSecondPrize.Text = comp.SecondPrize;
        txtThirdPrize.Text = comp.ThirdPrize;
        txtCompetitionStartDate.Text = comp.StartDate;
        txtCompetitionEndDate.Text = comp.EndDate;
        txtCompetitionDescription.Text = comp.Description;
        txtCompetitionQuotation.Text = comp.Quotation;
        grvStaffList.DataSource = ds1.Tables[0];
        grvStaffList.DataBind();
    }
    private Competition getComp()
    {
        ManagerBUS m = new ManagerBUS();
        Competition comp = new Competition();
        id = Convert.ToInt16(Request.QueryString["id"].ToString());
        DataSet ds = new DataSet();
        ds = m.getStaffOfComp(id);
        comp = m.searchCompetitionById(id);
        return comp;
    }
    protected void btnAddComp_Click(object sender, EventArgs e)
    {
        Competition comp = new Competition();
        ManagerBUS m = new ManagerBUS();
        comp.ComId =Convert.ToInt16(Request.QueryString["id"]);
        comp.Name = txtCompetitionName.Text;
        comp.PostDate = DateTime.Now.Date.ToString();
        comp.StartDate = txtCompetitionStartDate.Text;
        comp.EndDate = txtCompetitionEndDate.Text;
        comp.Description = txtCompetitionDescription.Text;
        comp.Quotation = txtCompetitionQuotation.Text;
        comp.FirstPrize = txtFirstPrize.Text;
        comp.SecondPrize = txtSecondPrize.Text;
        comp.ThirdPrize = txtThirdPrize.Text;
        comp.Manager.Id = Convert.ToInt16(Session["Id"]);
        if (m.updateCompetition(comp))
        {
            Response.Redirect("~/Pages/HomePage/Success.aspx");
        }
    }
}